*****************************************************************************************************************
* Files for the replication of "The Differential Impact of Threats on Ethnic Prejudice toward 
*	Three Minority Groups in Britain"
* Eline A. de Rooij, Matthew J. Goodwin, and Mark Pickup
* Political Science Research and Methods (PSRM)  
* Date: May 5 2017

*****************************************************************************************************************
*   2011 Analysis	
*****************************************************************************************************************

* The following analyses were carried out using Stata/SE 14.2 for Windows (64-bit x86-64) 

* download .dta files into new personal folder and specify it as the working directory:
cd "C:\Users\..." 
** NOTE: insert correct link to folder between " " 

* open data (from folder set as working directory):
use "De Rooij et al. 2017 PSRM replication_2011.dta" , clear


*********************************************************************
* RECODES
*********************************************************************

* create treatment variable for coupled/decoupled threat items
gen treatment = 1 if G1s1 == 1
replace treatment = 0 if G2s2 == 1
label var treatment "received coupled threat items"
label define treatl 0 "received decoupled items" 1 "received coupled items"
label value treatment treatl

* threat1
gen threat1 = g1q1
replace threat1 = g2q1 if g2q1<=5
recode threat1 (5=.) (1=4) (4=1) (2=3) (3=2)

* threat2
gen threat2 = g1q2
replace threat2 = g2q2 if g2q2<=5
recode threat2 (5=.) (1=4) (4=1) (2=3) (3=2)

* threat3
gen threat3 = g1q3
replace threat3 = g2q3 if g2q3<=5
recode threat3 (5=.) (1=4) (4=1) (2=3) (3=2)

* threat4
gen threat4 = g1q4
replace threat4 = g2q4 if g2q4<=5
recode threat4 (5=.) (1=4) (4=1) (2=3) (3=2)

* threat5
gen threat5 = g1q5
replace threat5 = g2q5 if g2q5<=5
recode threat5 (5=.) (1=4) (4=1) (2=3) (3=2)

* threat6
gen threat6 = g1q6
replace threat6 = g2q6 if g2q6<=5
recode threat6 (5=.) 

* threat7
gen threat7 = g1q7
replace threat7 = g2q7 if g2q7<=5
recode threat7 (5=.) 

label var threat1 "Violence in Neighbourhood"
label var threat2 "Individual Economic"
label var threat3 "Violence in Society"
label var threat4 "British Culture"
label var threat5 "Collective Economic"
label var threat6 "Britain Better"
label var threat7 "Neighbourhood Nicer"

label define threatl 1 "strongly disagree" 2 "tend to disagree" 3 "tend to agree" 4 "strongly agree"
label value threat1 threatl
label value threat2 threatl
label value threat3 threatl
label value threat4 threatl
label value threat5 threatl
label define threatl2 4 "strongly disagree" 3 "tend to disagree" 2 "tend to agree" 1 "strongly agree"
label value threat6 threatl2
label value threat7 threatl2

* economy
gen retrofin = fiq1
recode retrofin(6=.)
label var retrofin "financial situation of household compared to 12 months ago"
label define retrofin 1 "got a lot worse" 2 "got a little worse" 3 "stay the same" 4 "got a little better" 5 "got a lot better"
label value retrofin retrofin

gen retroecon = fiq2
recode retroecon (6=.)
label var retroecon "general economic situation in country compared to 12 months ago"
label define retroecon 1 "got a lot worse" 2 "got a little worse" 3 "stay the same" 4 "got a little better" 5 "got a lot better"
label value retroecon retroecon

gen prosfin = fiq3
recode prosfin(6=.)
label var prosfin "expected change of financial situation of household"
label define prosfin 1 "get a lot worse" 2 "get a little worse" 3 "stay the same" 4 "get a little better" 5 "get a lot better"
label value prosfin prosfin

gen prosecon = fiq4
recode prosecon (6=.)
label var prosecon "expected change of economic situation in country"
label define prosecon 1 "get a lot worse" 2 "get a little worse" 3 "stay the same" 4 "get a little better" 5 "get a lot better"
label value prosecon prosecon

* education
gen edu_age=Education_age
recode edu_age (7=.) (1=15) (2=16) (3=17.5) (4=19) (5=20)
replace edu_age=Age if edu_age==6
recode edu_age (21/100 = 20)
label var edu_age "terminal age of education"

* age already exists (no missing)
tab Age

* female (no missing)
recode Gender (1=0 "male") (2=1 "female"), into(female)

* social grade already exists (no missing)
tab SocialGrade

* work status already exists, but 31 missing (coded with missing value code .a)
** Note: to be recoded after imputation
tab Work_status

* UKborn
recode Born (1=1 "inside the UK (ENG, WAL, SCO, NIR)") (2=0 "outside the UK") (3=.), gen(UKborn)
label var UKborn "born inside the UK"

* ethnicity already exists
tab Ethnicity if Ethnicity<2
* white British only

* British identity: NOTE: Mark used only one question (g13q2) in riots paper... ?
recode g13q1 (5=.) (1=4) (4=1) (2=3) (3=2), gen(Bid1)
recode g13q2 (5=.) (1=4) (4=1) (2=3) (3=2), gen(Bid2)
recode g13q3 (5=.) (1=4) (4=1) (2=3) (3=2), gen(Bid3)
recode g13q4 (5=.) (1=4) (4=1) (2=3) (3=2), gen(Bid4)
label define Bidl 1 "strongly disagree" 2 "tend to disagree" 3 "tend to agree" 4 "strongly agree"
label value Bid1 Bidl
label value Bid2 Bidl
label value Bid3 Bidl
label value Bid4 Bidl

* authoritarianism
recode g11q1 (5=.) (1=4) (4=1) (2=3) (3=2), gen(auth1)
recode g11q2 (5=.) (1=4) (4=1) (2=3) (3=2), gen(auth2)
recode g11q3 (5=.) (1=4) (4=1) (2=3) (3=2), gen(auth3)
label define authl 1 "strongly disagree" 2 "tend to disagree" 3 "tend to agree" 4 "strongly agree"
label value auth1 authl
label value auth2 authl
label value auth3 authl

* self-esteem
recode g12q1 (1=1 "True") (2=0 "False") (3=.), gen(est1)
recode g12q2 (1=1 "True") (2=0 "False") (3=.), gen(est2)
recode g12q3 (1=1 "True") (2=0 "False") (3=.), gen(est3)
recode g12q4 (1=1 "True") (2=0 "False") (3=.), gen(est4)
recode g12q5 (1=1 "True") (2=0 "False") (3=.), gen(est5)

* group hostility
recode g7q1 (5=.) (1=1) (2=2) (3=3) (4=4), gen(GHbb1)
recode g7q2 (5=.) (1=4) (4=1) (2=3) (3=2), gen(GHbb2)
recode g7q3 (5=.) (1=1) (2=2) (3=3) (4=4), gen(GHbb3)
recode g7q4 (5=.) (1=4) (4=1) (2=3) (3=2), gen(GHbb4)
recode g7q5 (5=.) (1=4) (4=1) (2=3) (3=2), gen(GHbb5)
recode g7q6 (5=.) (1=4) (4=1) (2=3) (3=2), gen(GHbb6)
recode g7q7 (5=.) (1=4) (4=1) (2=3) (3=2), gen(GHbb7)
recode g7q8 (5=.) (1=4) (4=1) (2=3) (3=2), gen(GHbb8)

recode g8q1 (5=.) (1=1) (2=2) (3=3) (4=4), gen(GHmu1)
recode g8q2 (5=.) (1=4) (4=1) (2=3) (3=2), gen(GHmu2)
recode g8q3 (5=.) (1=1) (2=2) (3=3) (4=4), gen(GHmu3)
recode g8q4 (5=.) (1=4) (4=1) (2=3) (3=2), gen(GHmu4)
recode g8q5 (5=.) (1=4) (4=1) (2=3) (3=2), gen(GHmu5)
recode g8q6 (5=.) (1=4) (4=1) (2=3) (3=2), gen(GHmu6)
recode g8q7 (5=.) (1=4) (4=1) (2=3) (3=2), gen(GHmu7)
recode g8q8 (5=.) (1=4) (4=1) (2=3) (3=2), gen(GHmu8)

recode g9q1 (5=.) (1=1) (2=2) (3=3) (4=4), gen(GHee1)
recode g9q2 (5=.) (1=4) (4=1) (2=3) (3=2), gen(GHee2)
recode g9q3 (5=.) (1=1) (2=2) (3=3) (4=4), gen(GHee3)
recode g9q4 (5=.) (1=4) (4=1) (2=3) (3=2), gen(GHee4)
recode g9q5 (5=.) (1=4) (4=1) (2=3) (3=2), gen(GHee5)
recode g9q6 (5=.) (1=4) (4=1) (2=3) (3=2), gen(GHee6)
recode g9q7 (5=.) (1=4) (4=1) (2=3) (3=2), gen(GHee7)
recode g9q8 (5=.) (1=4) (4=1) (2=3) (3=2), gen(GHee8)

recode g10q1 (5=.) (1=1) (2=2) (3=3) (4=4), gen(GHwb1)
recode g10q2 (5=.) (1=4) (4=1) (2=3) (3=2), gen(GHwb2)
recode g10q3 (5=.) (1=1) (2=2) (3=3) (4=4), gen(GHwb3)
recode g10q4 (5=.) (1=4) (4=1) (2=3) (3=2), gen(GHwb4)
recode g10q5 (5=.) (1=4) (4=1) (2=3) (3=2), gen(GHwb5)
recode g10q6 (5=.) (1=4) (4=1) (2=3) (3=2), gen(GHwb6)
recode g10q7 (5=.) (1=4) (4=1) (2=3) (3=2), gen(GHwb7)
recode g10q8 (5=.) (1=4) (4=1) (2=3) (3=2), gen(GHwb8)

* social distance 
recode g4q1 (5=.) (1=1 "very attractive") (2=2 "fairly attractive") (3=3 "fairly unattractive") (4=4 "very unattractive"), gen(SDbb1)
recode g4q2 (5=.) (1=1 "very attractive") (2=2 "fairly attractive") (3=3 "fairly unattractive") (4=4 "very unattractive"), gen(SDbb2)
recode g4q3 (5=.) (1=1 "very attractive") (2=2 "fairly attractive") (3=3 "fairly unattractive") (4=4 "very unattractive"), gen(SDbb3)

recode g5q1 (5=.) (1=1 "very attractive") (2=2 "fairly attractive") (3=3 "fairly unattractive") (4=4 "very unattractive"), gen(SDmu1)
recode g5q2 (5=.) (1=1 "very attractive") (2=2 "fairly attractive") (3=3 "fairly unattractive") (4=4 "very unattractive"), gen(SDmu2)
recode g5q3 (5=.) (1=1 "very attractive") (2=2 "fairly attractive") (3=3 "fairly unattractive") (4=4 "very unattractive"), gen(SDmu3)

recode g6q1 (5=.) (1=1 "very attractive") (2=2 "fairly attractive") (3=3 "fairly unattractive") (4=4 "very unattractive"), gen(SDee1)
recode g6q2 (5=.) (1=1 "very attractive") (2=2 "fairly attractive") (3=3 "fairly unattractive") (4=4 "very unattractive"), gen(SDee2)
recode g6q3 (5=.) (1=1 "very attractive") (2=2 "fairly attractive") (3=3 "fairly unattractive") (4=4 "very unattractive"), gen(SDee3)


*********************************************************************
* TABLE A.2A IN THE APPENDIX:
*	Descriptive Statistics of Independent Variables, 2011 
*	(before multiple imputation) 
*********************************************************************

* keep only White British respondents:
keep if Ethnicity==1
* Note: 168 respondents deleted

* descriptives before imputation, for non-imputed variables only
** NOTE: temporarily create i.work_status and Bidentity_2, then delete and re-do after imputation

* work status (already 31 missing in original code (coded with missing value code .a)
recode Work_status (1=1) (2/3 =2) (4=3) (5=4) (6=5) (7/8 = 6), into(work_status)
label define work_status 1 "working full time" 2 "working part time" 3 "full time student" 4 "retired" 5 "unemployed" 6 "not working"
label value work_status work_status
label var work_status "working status"
* British identity
egen Bidentity_2 = rowmean(Bid1-Bid4)

* decoupled threats:
sum threat1 threat2 threat3 threat4 threat5 if treatment==0
* coupled threats:
sum threat1 threat2 threat3 threat4 threat5 if treatment==1
* other:
sum female Age edu_age i.SocialGrade i.work_status UKborn Bidentity_2 retroecon retrofin 
** to obtain descriptives for first categories of SocialGrade and work_status:
sum ib(last).SocialGrade ib(last).work_status 

drop work_status Bidentity_2


*********************************************************************
* TABLE A.4A IN THE APPENDIX:  
*	Associations between Threats under Coupled and Decoupled Conditions, 2011
*********************************************************************

* In order to estimate correlations and their level of significance with survey data:
* (1) use correlate with aweights for point estimates of the correlation
* (2) use svy: regress for p-values 
*	Do svy: regress y x and svy: regress x y and take the biggest p-value, which is the conservative thing to do

* decoupled
pwcorr threat1 threat2 threat3 threat4 threat5 if treatment==0 [aweight=W8], sig obs
* coupled
pwcorr threat1 threat2 threat3 threat4 threat5 if treatment==1 [aweight=W8], sig obs
svyset [pweight=W8]
svy: reg threat1 threat2 if treatment==0 
svy: reg threat2 threat1 if treatment==0 
svy: reg threat1 threat3 if treatment==0 
svy: reg threat3 threat1 if treatment==0 
svy: reg threat1 threat4 if treatment==0 
svy: reg threat4 threat1 if treatment==0 
svy: reg threat1 threat5 if treatment==0
svy: reg threat5 threat1 if treatment==0 
svy: reg threat2 threat3 if treatment==0
svy: reg threat3 threat2 if treatment==0
svy: reg threat2 threat4 if treatment==0 
svy: reg threat4 threat2 if treatment==0 
svy: reg threat2 threat5 if treatment==0 
svy: reg threat5 threat2 if treatment==0 
svy: reg threat3 threat4 if treatment==0 
svy: reg threat4 threat3 if treatment==0 
svy: reg threat3 threat5 if treatment==0 
svy: reg threat5 threat3 if treatment==0 
svy: reg threat4 threat5 if treatment==0 
svy: reg threat5 threat4 if treatment==0 

svy: reg threat1 threat2 if treatment==1 
svy: reg threat2 threat1 if treatment==1 
svy: reg threat1 threat3 if treatment==1 
svy: reg threat3 threat1 if treatment==1 
svy: reg threat1 threat4 if treatment==1 
svy: reg threat4 threat1 if treatment==1 
svy: reg threat1 threat5 if treatment==1 
svy: reg threat5 threat1 if treatment==1 
svy: reg threat2 threat3 if treatment==1 
svy: reg threat3 threat2 if treatment==1 
svy: reg threat2 threat4 if treatment==1 
svy: reg threat4 threat2 if treatment==1 
svy: reg threat2 threat5 if treatment==1 
svy: reg threat5 threat2 if treatment==1 
svy: reg threat3 threat4 if treatment==1 
svy: reg threat4 threat3 if treatment==1 
svy: reg threat3 threat5 if treatment==1 
svy: reg threat5 threat3 if treatment==1 
svy: reg threat4 threat5 if treatment==1 
svy: reg threat5 threat4 if treatment==1

svyset, clear


*********************************************************************
* MULTIPLE IMPUTATION
*********************************************************************

* impute (use recoded var in which missing (often code 5) is set to missing "." 
* only exception is Work_status as there is more info in original variable

set seed 974302623
mi set mlong
mi register imputed auth1 auth2 auth3 est1 est2 est3 est4 est5 GHbb1 GHbb2 GHbb3 GHbb4 GHbb5 GHbb6 GHbb7 GHbb8 GHmu1 GHmu2 GHmu3 GHmu4 GHmu5 GHmu6 GHmu7 GHmu8 GHee1 GHee2 GHee3 GHee4 GHee5 GHee6 GHee7 GHee8 GHwb1 GHwb2 GHwb3 GHwb4 GHwb5 GHwb6 GHwb7 GHwb8 SDbb1 SDbb2 SDbb3 SDmu1 SDmu2 SDmu3 SDee1 SDee2 SDee3
mi impute mvn auth1 auth2 auth3 est1 est2 est3 est4 est5 GHbb1 GHbb2 GHbb3 GHbb4 GHbb5 GHbb6 GHbb7 GHbb8 GHmu1 GHmu2 GHmu3 GHmu4 GHmu5 GHmu6 GHmu7 GHmu8 GHee1 GHee2 GHee3 GHee4 GHee5 GHee6 GHee7 GHee8 GHwb1 GHwb2 GHwb3 GHwb4 GHwb5 GHwb6 GHwb7 GHwb8 SDbb1 SDbb2 SDbb3 SDmu1 SDmu2 SDmu3 SDee1 SDee2 SDee3 = female Age edu_age i.SocialGrade i.Work_status UKborn i.threat1 i.threat2 i.threat3 i.threat4 i.threat5 i.threat6 i.threat7 retrofin retroecon prosfin prosecon Bid1 Bid2 Bid3 Bid4 treatment, add(10) force initmcmc(em, iterate(400))
display c(seed)
/* state of random-number generator is: 
XAA9652417f36b6e8a56a545688a3c265d3f6191fbb5ab1b057978c86d92df0d9cbaadb6c90381cbd4ea26f2948b718b1c54639426
> 585e6b4254f6a77f540ed548d27e0a28cb6d93c7114d31afaec8de1088dac78b359463bbb39675a332ad7c603debcc3ba3b3eecf
> 1be2faf6b33278fc5775adc65c9b0682dbf82e7849b13670273ed51b92add4ec8bdace9fbbb04847cd780164ab60b7e0fd812f0d
> 3c4e916ed5b9549092ca9002226ce63cf7f39c89a17f9a0559e5a494bf02f6490728fa558e8af97ee3193d6f17d7ba60698cf64e
> af0ab5b942e03f2f0bda130099c68f10167f088e581e6df7106d11196b6e23d54e5d9ac4915194cf1f3d12a91505c0121fb95bc4
> 6445440ce504dba35058e262cb9ee34ef2f8509d38bd41b47db459f3978fe145a6254a35e1552496b99be36836b2f0c20a65a7c8
> ecebfdb117fef5aa1179c61a4e0efe1e8353138f55968bbd72b599ef427ada333e217ae9ba8ebccbf79a224b0132dd11a18ab214
> a7a0e3e30a86e708277f24028f38ff01f9daa90416f9352f82f5fefda4a856b735012b9cb1e9a77e38b1c9b4cbcaf900f368d3c2
> ff234d89648348276cbdd6ec265ba98a9790c9b2cdbf2b68c0dc2a502e35b980957e6db2794446e81e80b991a5ea6573cd83b0f6
> 5cad807307626039b82399c7aea1280dca9e4d255cc660d0ed1b828b94c7cb4340056d178effa8b2e75401960bd04cd904115131
> dff6e83e3fcfee390c26c96587d373d399ce8ffbd95334638b424512600e047b09a0cd80812cb1c77b52e150904bcaf07a2e442b
> 5382358131961afb9753905df035ced664915e3ba786927e7471d330d73b7f8ee7afbc00cf9ad64a2de7950f38e35ac9e1c9c289
> 8c816a2accde4524497de0936dabc3ee35eb593f5e9a5d04264512e3c6090c0ae4f85c5d9dbd03e86c5af19a32a512e9605360c2
> 2823b41983ddbbe66daab744cea988d7b37b8f59f70e6e2b909567fc6d7ef5c6512f770b039f263b6f53702ef36fca42d8f0a950
> 8b50eb62c03793c563e9803a0f7d8b41c70cb6e18f3ff761913ae84010a47e15e99f444eed85a5d6003a7a8c09f8480ffb3ffc86
> 2634150a0c0ac7ba29088a2a31c16521bf04c402604362eda3eaba97154416d31c6522a8b7ea818b098306c3aff3061dba0e08fe
> 0d85ea701885aa46d26e9bd7ff81435d2a3a024929d188272e35b3835afa018cc1f9f75d29fd30987145e6c9a75bfb756dc1d19e
> 366f6559ff806f19ccd2cdc8a986fc10662619e06b476ba956ac92cff38876432a3081718687fcacbbc026b629ed0f38b2db4e05
> 2435a2c92dea3230be8804785629c4a4faa3dadd10355ecd1945ba83c20c819e34028fa4356b1fa43218202c6bf7af46f9f32f2a
> ec81579e4c44439e72db00642fea05bd5230d795326714b8974fe33c3638183fe20a467bbb285fd63d5a24311b17a4d49bc71da6
> b5a130730ccbcabeac12d86b5be1b426366bddf341777717d129e713c9056ed58d75050ef4b0e9156ac2dd527b42a4c24a3ef458
> 096848bedd4d06b7095a9b141b148d19a81689fb64031d1c9ee476218289bbfac6ae59329f11a540711fd1c7c1cc0a48f60d6898
> e2a83de824760478ba2300ec059c569715b0922984a7950008ea093a895a0cfa53b736874fdb45d51b42110ebcff0d6a7f0a3f45
> b4e1f7daab227fd71eb7669306949139dc53b63c55f868b76d47f5f57da044abc64c533936e70e9ed8cbcf70a33f2e9de1112712
> 7d9a73df3bfb83b2a2e741add72832143d1e399967dea03658e1b29f9e277efad4577394bb117374010f9e3e07da40c46b5f381f
> 13aa89f58242a17ff05579c209c902315394856d0340e4a34063fb1272511b240a07eea3864adbe70815996f849ac1f94156487c
> cbb950274506f6af1032767b1a2b011fa2923683587ba2ae76d33ca82bee4a097d06bdd0dff2d418bca27209445249af6976104c
> 7e7dd28ed40ccbae40bd5ce40a539acc95ae91714e1f71a3093b6880ae8bd7cf1f4e359dc8d71fed8b875d80a634cde3d73853c1
> ceafd8fd88a9cda2a2fd99f6f476b0084617e9038f7941ae12a8fc25548964e72663f327a13933bc6709127297d87c56ef81bed4
> e15d9b49681278da02b877280a2b6b8d5e0b934717f93caab5cb0629e8d9079dfcc39fff49ec3f2820b81d97f7a9d632ca845607
> 7b8012b8b6959e15d37c6064f3801685565219de5737c7a7707c5efacc5f8f4e85ce8acbb0e44b422868f1bbb56ca5b25e67c73b
> 4241f357535424a9d07dca5806d165c0f6a78eb826b975af3e29cca7322dfb6fb7250f7e42f79950c85a7c34c6b1cbafa9c8871b
> 8bf0dc4a9058ba554a14b9ff3bde8a926edef326592b573c3435de45599c6cbbed208c0b94aab83a708643c568d28061f35358cc
> bf78ac9f3469357d763f966e63e11179bfe3e36d24101d68a9b1c10894959c703b32c050fcfa5980f27c178dafb64de081e7098b
> 29a904ec8cc61723bc7dbb05fb5e5c09a421ac7cd0ef394bebb2c42930b041537e1b56beb2b23dd47a2b24e3dad668afbeffea48
> f34d36327208136a71b12f5f7e64ccc70c3a3b240375b601a37a0abcd48f059a29a66456eee37e31f4e7af9ab4e0f41e048a2f41
> 17a735c38fb23cb1d19ea4e76fda5a51d22a5b30f09e9a93ec806e9d3d13ccae3ce9bd4eee1eb9aee6913cace67532e19ca046ae
> 0004a587f40e88c92ad0de146476e448e4b5452dd794092587b532983e4bd2b9c6206a61290b94f4950e4d5315795625b8efff45
> 3a9e3e1d3d3a6450ea038574b84c9ed597fba69115781a0816fe457ac7c63fab08e8991e12a7823d4fd36e1f895e5aa4f45ca102
> 71d0e338908948dce443c323fc7ed5175c07971e5cd6767981a9c3da2c4f7e2404ecb7c8f6c2c6e5a8a2107e8395e5a9325fd816
> 0dc62d5c232bf3d80c94df393980af11a69815f55fc15e011748e10f5d34dbd3aa2d63d96d6db38849025865450835d5d75b9274
> bf32ccba3f7d28c5d1311c9d25ed00e9dbf63e1f07428aa141f08ed0814b3d0e1246fa23174f8bdaaf4a428a3a141054cd4f1376
> da973294632a58250ca0e8008df72e0fcfad429f4297ea56345f88386b3571c3ed1548c025df7f2daf4b41f5281a161374c6dffc
> 28e460eb11c057c6fdc46fa319089a42fd98ab837424ad353fdc0fa14654e1ede5c235baa6c62da982031c6f23e39956b4baafc6
> 2357ca5a99c2342096c3f5ceebd51ce178e34fcbf1a31998ce5c04895bebb19f2d9c72887fcb045c42336dce3c26efe42ba29ca3
> f404541b3a5d369fdfb7438cfa699546e480c4b5f7681a6274368cbd35b3b45cf6d082f916dfdc7338da0ae5f806b364ddc4ca32
> f3ec61347def241159a77bc505fc08c3a80ded345a6506a7fb340505cfc1411fdfc23f1ae9a4b48a7d85bc9d7beae4063321ac03
> 8538ad895081b6d1a3b499b7163ca90008c0d66562bf94386e60f4eaaf66df5895463344115c33efbe43e00b5c6260b66632f1c9
> c0001000000c845c0
*/

save "W1 imputed.dta"


*********************************************************************
* FURTHER RECODES AND DESCRIPTIVES
*********************************************************************

* work status (already 31 missing in original code (coded with missing value code .a)
recode Work_status (1=1) (2/3 =2) (4=3) (5=4) (6=5) (7/8 = 6), into(work_status)
label value work_status work_status
label var work_status "working status"

* British identity - 2 versions
gen Bidentity = (Bid1 + Bid2 + Bid3 + Bid4)/4
** excludes all respondents with 1 or more missing
egen Bidentity_2 = rowmean(Bid1-Bid4)
** takes average over valid items, only excludes those with 4 missing
sum Bidentity Bidentity_2
** lower mean on _2

* authoritarian values, self-esteem and social distance
gen authvalues = (auth1+ auth2+ auth3)/3 
gen selfest = (est1+ est2 +est3 +est4+ est5)/5  
gen SDblack =  (SDbb1+ SDbb2+ SDbb3)/3 
gen SDMus =  (SDmu1 +SDmu2 +SDmu3)/3 
gen SDEEur =  (SDee1 +SDee2 +SDee3)/3
gen GHblack = (GHbb1 +GHbb2 +GHbb3 +GHbb4 +GHbb5 +GHbb6 +GHbb7 +GHbb8)/8
gen GHMus = (GHmu1 +GHmu2+ GHmu3 +GHmu4 +GHmu5 +GHmu6 +GHmu7 +GHmu8)/8
gen GHEEur = (GHee1 +GHee2 +GHee3+ GHee4 +GHee5 +GHee6+ GHee7+ GHee8)/8
gen GHwhite = (GHwb1 +GHwb2+ GHwb3 +GHwb4+ GHwb5 +GHwb6 +GHwb7+ GHwb8)/8

* weighting
mi svyset [pweight=W8]

* create variable indicating survey wave
gen wave=0
label define wave 0 "survey wave 1 (2011)" 1 "survey wave 4 (2016)"
label value wave wave
label var wave "survey wave"

save "W1 imputed.dta", replace


*********************************************************************
* TABLE A.3A IN THE APPENDIX:
*	Estimated Mean and Standard Error of Imputed Variables, 2011 
*********************************************************************

* descriptives: estimated mean and s.e.
mi estimate: svy: mean authvalues
mi estimate: svy: mean selfest	
mi estimate: svy: mean GHblack
mi estimate: svy: mean GHMus
mi estimate: svy: mean GHEEur
mi estimate: svy: mean GHwhite

* descriptives: minimum and maximum
sum authvalues selfest GHblack GHMus GHEEur GHwhite 


*********************************************************************
* TABLE A.5 IN THE APPENDIX:
*	Predictors of Threat under Coupled (C) and Decoupled (D) Conditions, 2011
*********************************************************************

* coupled
mi estimate: svy: oprobit threat1 female Age edu_age i.SocialGrade i.work_status UKborn Bidentity_2 retroecon retrofin authvalues selfest if treatment==1 
* decoupled
mi estimate: svy: oprobit threat1 female Age edu_age i.SocialGrade i.work_status UKborn Bidentity_2 retroecon retrofin authvalues selfest if treatment==0 

* coupled
mi estimate: svy: oprobit threat2 female Age edu_age i.SocialGrade i.work_status UKborn Bidentity_2 retroecon retrofin authvalues selfest if treatment==1 
* decoupled
mi estimate: svy: oprobit threat2 female Age edu_age i.SocialGrade i.work_status UKborn Bidentity_2 retroecon retrofin authvalues selfest if treatment==0 

* coupled
mi estimate: svy: oprobit threat3 female Age edu_age i.SocialGrade i.work_status UKborn Bidentity_2 retroecon retrofin authvalues selfest if treatment==1 
* decoupled
mi estimate: svy: oprobit threat3 female Age edu_age i.SocialGrade i.work_status UKborn Bidentity_2 retroecon retrofin authvalues selfest if treatment==0    

* coupled
mi estimate: svy: oprobit threat4 female Age edu_age i.SocialGrade i.work_status UKborn Bidentity_2 retroecon retrofin authvalues selfest if treatment==1 
* decoupled
mi estimate: svy: oprobit threat4 female Age edu_age i.SocialGrade i.work_status UKborn Bidentity_2 retroecon retrofin authvalues selfest if treatment==0  

* coupled
mi estimate: svy: oprobit threat5 female Age edu_age i.SocialGrade i.work_status UKborn Bidentity_2 retroecon retrofin authvalues selfest if treatment==1 
* decoupled
mi estimate: svy: oprobit threat5 female Age edu_age i.SocialGrade i.work_status UKborn Bidentity_2 retroecon retrofin authvalues selfest if treatment==0 


*********************************************************************
* TABLE A.7A IN THE APPENDIX:
*	Predictors of Group Hostility under Coupled (C) and Decoupled (D) Conditions, 2011; 
*	Threats Entered Individually
* FIGURE A.1A IN THE APPENDIX:
*	Unstandardized OLS Coefficient Estimates and 95% Confidence Intervals of the Impact of Coupled (C) 
* 	and Decoupled (D) Threats on Group Hostility, 2011; Threats Entered Individually
**	NOTE: for significance test see code for FIGURE A.1B below 
* FIGURE 1 IN THE PAPER (2011 estimates):
*	Unstandardized OLS Coefficient Estimates and 95% Confidence Intervals of the Impact of Threats
*	on Group Hostility; Threats Entered Individually
**	NOTE: for significance test of difference between 2011 and 2016 estimates, 
**	see code for FIGURE 1 below
*********************************************************************

* coupled
mi estimate: svy: reg GHblack threat1 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==1 
mi estimate: svy: reg GHblack threat2 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==1 
mi estimate: svy: reg GHblack threat3 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==1 
mi estimate: svy: reg GHblack threat4 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==1 
mi estimate: svy: reg GHblack threat5 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==1 

mi estimate: svy: reg GHMus threat1 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==1 
mi estimate: svy: reg GHMus threat2 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==1 
mi estimate: svy: reg GHMus threat3 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==1 
mi estimate: svy: reg GHMus threat4 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==1 
mi estimate: svy: reg GHMus threat5 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==1 

mi estimate: svy: reg GHEEur threat1 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==1 
mi estimate: svy: reg GHEEur threat2 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==1 
mi estimate: svy: reg GHEEur threat3 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==1 
mi estimate: svy: reg GHEEur threat4 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==1 
mi estimate: svy: reg GHEEur threat5 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==1 

mi estimate: svy: reg GHwhite threat1 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==1 
mi estimate: svy: reg GHwhite threat2 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==1 
mi estimate: svy: reg GHwhite threat3 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==1 
mi estimate: svy: reg GHwhite threat4 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==1 
mi estimate: svy: reg GHwhite threat5 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==1 

* decoupled
mi estimate: svy: reg GHblack threat1 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==0 
mi estimate: svy: reg GHblack threat2 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==0 
mi estimate: svy: reg GHblack threat3 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==0 
mi estimate: svy: reg GHblack threat4 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==0 
mi estimate: svy: reg GHblack threat5 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==0 

mi estimate: svy: reg GHMus threat1 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==0 
mi estimate: svy: reg GHMus threat2 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==0 
mi estimate: svy: reg GHMus threat3 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==0 
mi estimate: svy: reg GHMus threat4 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==0 
mi estimate: svy: reg GHMus threat5 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==0 

mi estimate: svy: reg GHEEur threat1 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==0 
mi estimate: svy: reg GHEEur threat2 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==0 
mi estimate: svy: reg GHEEur threat3 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==0 
mi estimate: svy: reg GHEEur threat4 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==0 
mi estimate: svy: reg GHEEur threat5 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==0 

mi estimate: svy: reg GHwhite threat1 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==0 
mi estimate: svy: reg GHwhite threat2 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==0 
mi estimate: svy: reg GHwhite threat3 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==0 
mi estimate: svy: reg GHwhite threat4 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==0 
mi estimate: svy: reg GHwhite threat5 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==0 


*********************************************************************
* DISCUSSION IN THE PAPER OF SOME ESTIMATES IN FIGURE 1 IN TERMS OF THE IMPACT 
* ON HOSTILITY OF ONE STANDARD DEVIATION (SD) INCREASE IN CULTURAL AND COLLECTIVE SAFETY THREAT:
**	NOTE: Only calculated for decoupled threat4 (GHBlack, GHMus, GHEEur) and threat3 (GHMus) 
*********************************************************************

* SD for threat4
mi estimate: svy: mean threat4
matrix b = e(b_mi)
scalar m = b[1,1]
gen threat4_v = (threat4 - m)^2 
mi estimate: svy: mean threat4_v
matrix b = e(b_mi)
scalar threat4_sd2 = b[1,1]

* SD for GHMus
mi estimate: svy: mean GHMus
matrix b = e(b_mi)
scalar m = b[1,1]
gen GHMus_v = (GHMus - m)^2 
mi estimate: svy: mean GHMus_v
matrix b = e(b_mi)
scalar GHMus_sd2 = b[1,1]

* Effect of threat4 on GHMus
mi estimate: svy: reg GHMus threat4 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==0 
matrix beta = e(b_mi)
display(sqrt(threat4_sd2)*beta[1,1])/sqrt(GHMus_sd2)
** Result: a one SD increase in cultural threat is predicted to produce a .43826968 SD increase in GHMus

* SD for GHEEur
mi estimate: svy: mean GHEEur
matrix b = e(b_mi)
scalar m = b[1,1]
gen GHEEur_v = (GHEEur - m)^2 
mi estimate: svy: mean GHEEur_v
matrix b = e(b_mi)
scalar GHEEur_sd2 = b[1,1]

* Effect of threat4 on GHEEur
mi estimate: svy: reg GHEEur threat4 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==0 
matrix beta = e(b_mi)
display(sqrt(threat4_sd2)*beta[1,1])/sqrt(GHEEur_sd2)
** Result: a one SD increase in cultural threat is predicted to produce a .30593501 SD increase in GHEEur

* SD for GHblack
mi estimate: svy: mean GHblack
matrix b = e(b_mi)
scalar m = b[1,1]
gen GHblack_v = (GHblack - m)^2 
mi estimate: svy: mean GHblack_v
matrix b = e(b_mi)
scalar GHblack_sd2 = b[1,1]

* Effect of threat4 on GHBlack
mi estimate: svy: reg GHblack threat4 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==0 
matrix beta = e(b_mi)
display(sqrt(threat4_sd2)*beta[1,1])/sqrt(GHblack_sd2)
** Result: a one SD increase in cultural threat is predicted to produce a .32141382 SD increase in GHBlack

* SD for threat3
mi estimate: svy: mean threat3
matrix b = e(b_mi)
scalar m = b[1,1]
gen threat3_v = (threat3 - m)^2 
mi estimate: svy: mean threat3_v
matrix b = e(b_mi)
scalar threat3_sd2 = b[1,1]

* Effect of threat3 on GHMus
mi estimate: svy: reg GHMus threat3 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==0 
matrix beta = e(b_mi)
display(sqrt(threat3_sd2)*beta[1,1])/sqrt(GHMus_sd2)
** Result: a one SD increase in collective safety threat is predicted to produce a .22325173 SD increase in GHMus

drop threat4_v-threat3_v


*********************************************************************
* FIGURE A.1B IN THE APPENDIX:
*	Difference in Unstandardized OLS Coefficient Estimates and 95% Confidence Intervals 
*	of the Impact of Coupled (C) and Decoupled (D) Threats on Group Hostility, 2011; 
*	Threats Entered Individually
*********************************************************************

* NOTE: The estimates and confidence intervals shown in FIGURE A.1B are those for the c.threat[]##treatment interaction effects 

mi estimate: svy: reg GHblack c.threat1##treatment female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest 
mi estimate: svy: reg GHblack c.threat2##treatment female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest 
mi estimate: svy: reg GHblack c.threat3##treatment female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest 
mi estimate: svy: reg GHblack c.threat4##treatment female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest 
mi estimate: svy: reg GHblack c.threat5##treatment female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest 

mi estimate: svy: reg GHMus c.threat1##treatment female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest 
mi estimate: svy: reg GHMus c.threat2##treatment female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest 
mi estimate: svy: reg GHMus c.threat3##treatment female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest 
mi estimate: svy: reg GHMus c.threat4##treatment female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest 
mi estimate: svy: reg GHMus c.threat5##treatment female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest 

mi estimate: svy: reg GHEEur c.threat1##treatment female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest 
mi estimate: svy: reg GHEEur c.threat2##treatment female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest 
mi estimate: svy: reg GHEEur c.threat3##treatment female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest 
mi estimate: svy: reg GHEEur c.threat4##treatment female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest  
mi estimate: svy: reg GHEEur c.threat5##treatment female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest  

mi estimate: svy: reg GHwhite c.threat1##treatment female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest 
mi estimate: svy: reg GHwhite c.threat2##treatment female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest 
mi estimate: svy: reg GHwhite c.threat3##treatment female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest 
mi estimate: svy: reg GHwhite c.threat4##treatment female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest 
mi estimate: svy: reg GHwhite c.threat5##treatment female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest 


*********************************************************************
* TABLE A.8A IN THE APPENDIX:
*	Predictors of Group Hostility under Decoupled Condition, 2011; with Covariates Shown
* FIGURE A.2 IN THE APPENDIX:
*	Unstandardized OLS Coefficient Estimates and 95% Confidence Intervals of the Impact of  
* 	Threats on Group Hostility; Threats Entered Simultaneously (2011 estimates)
**	NOTE: for significance test of difference between 2011 and 2016 estimates, 
**	see code for FIGURE A.2 below 
*********************************************************************

mi estimate: svy: reg GHblack threat1 threat2 threat3 threat4 threat5 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==0 
mi estimate: svy: reg GHMus threat1 threat2 threat3 threat4 threat5 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==0 
mi estimate: svy: reg GHEEur threat1 threat2 threat3 threat4 threat5 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==0
mi estimate: svy: reg GHwhite threat1 threat2 threat3 threat4 threat5 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==0


*********************************************************************
* TABLE A.9A IN THE APPENDIX:
*	Predictors of Group Hostility under Decoupled Condition, 2011; with Hostility Toward White British
* FIGURE 2 IN THE PAPER (2011 estimates):
*	Unstandardized OLS Coefficient Estimates and 95% Confidence Intervals of the Impact of Threats
*	on Group Hostility; Threats Entered Simultaneaously and with Hostility Toward White British
**	NOTE: for significance test of difference between 2011 and 2016 estimates, 
**	see code for FIGURE 2 below 
*********************************************************************

mi estimate: svy: reg GHblack GHwhite threat1 threat2 threat3 threat4 threat5 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==0 
mi estimate: svy: reg GHMus GHwhite threat1 threat2 threat3 threat4 threat5 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==0 
mi estimate: svy: reg GHEEur GHwhite threat1 threat2 threat3 threat4 threat5 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest if treatment==0


*****************************************************************************************************************
*   2016 analysis	
*****************************************************************************************************************

* open data (from folder set as working directory):
use "De Rooij et al. 2017 PSRM replication_2016.dta" , clear


*********************************************************************
* RECODES
*********************************************************************

* threat1
recode Q1a (5=.) (1=4 "strongly agree") (4=1 "strongly disagree") (2=3 "tend to agree") (3=2 "tend to disagree"), gen(threat1)
* threat2
recode Q1b (5=.) (1=4 "strongly agree") (4=1 "strongly disagree") (2=3 "tend to agree") (3=2 "tend to disagree"), gen(threat2)
* threat3
recode Q1c (5=.) (1=4 "strongly agree") (4=1 "strongly disagree") (2=3 "tend to agree") (3=2 "tend to disagree"), gen(threat3)
* threat4
recode Q1d (5=.) (1=4 "strongly agree") (4=1 "strongly disagree") (2=3 "tend to agree") (3=2 "tend to disagree"), gen(threat4)
* threat5
recode Q1e (5=.) (1=4 "strongly agree") (4=1 "strongly disagree") (2=3 "tend to agree") (3=2 "tend to disagree"), gen(threat5)
* threat6
recode Q1f (5=.) (1=1 "strongly agree") (4=4 "strongly disagree") (2=2 "tend to agree") (3=3 "tend to disagree"), gen(threat6)
* threat7
recode Q1g (5=.) (1=1 "strongly agree") (4=4 "strongly disagree") (2=2 "tend to agree") (3=3 "tend to disagree"), gen(threat7)

label var threat1 "Violence in Neighbourhood"
label var threat2 "Individual Economic"
label var threat3 "Violence in Society"
label var threat4 "British Culture"
label var threat5 "Collective Economic"
label var threat6 "Britain Better"
label var threat7 "Neighbourhood Nicer"

* education
gen edu_age=Education_age
recode edu_age (7=.) (1=15) (2=16) (3=17.5) (4=19) (5=20)
replace edu_age=Age if edu_age==6
recode edu_age (21/100 = 20)
label var edu_age "terminal age of education"

* age already exists (no missing)
tab Age

* female (no missing)
recode Gender (1=0 "male") (2=1 "female"), into(female)

* social grade already exists, but different from w1 (no missing) so recode to match
tab Socialgrade
recode Socialgrade (1 2=1 "AB") (3=2 "C1") (4=3 "C2") (5 6=4 "DE"), gen(SocialGrade)

* work status already exists (no missing)
** Note: to be recoded after imputation
tab Work_stat

* UKborn
recode Birthplace (1=1 "inside the UK (ENG, WAL, SCO, NIR)") (2=0 "outside the UK") (3=.), gen(UKborn)
label var UKborn "born inside the UK"

* ethnicity already exists
tab Ethnicity if Ethnicity<2
** white British only

* authoritarianism
recode Q2a (5=.) (1=4) (4=1) (2=3) (3=2), gen(auth1)
recode Q2b (5=.) (1=4) (4=1) (2=3) (3=2), gen(auth2)
recode Q2c (5=.) (1=4) (4=1) (2=3) (3=2), gen(auth3)
label define authl 1 "strongly disagree" 2 "tend to disagree" 3 "tend to agree" 4 "strongly agree"
label value auth1 authl
label value auth2 authl
label value auth3 authl

* self-esteem
recode Q3a (1=1 "True") (2=0 "False") (3=.), gen(est1)
recode Q3b (1=1 "True") (2=0 "False") (3=.), gen(est2)
recode Q3c (1=1 "True") (2=0 "False") (3=.), gen(est3)
recode Q3d (1=1 "True") (2=0 "False") (3=.), gen(est4)
recode Q3e (1=1 "True") (2=0 "False") (3=.), gen(est5)

* group hostility
recode Qblack1 (5=.) (1=1) (2=2) (3=3) (4=4), gen(GHbb1)
recode Qblack2 (5=.) (1=4) (4=1) (2=3) (3=2), gen(GHbb2)
recode Qblack3 (5=.) (1=1) (2=2) (3=3) (4=4), gen(GHbb3)
recode Qblack4 (5=.) (1=4) (4=1) (2=3) (3=2), gen(GHbb4)
recode Qblack5 (5=.) (1=4) (4=1) (2=3) (3=2), gen(GHbb5)
recode Qblack6 (5=.) (1=4) (4=1) (2=3) (3=2), gen(GHbb6)
recode Qblack7 (5=.) (1=4) (4=1) (2=3) (3=2), gen(GHbb7)
recode Qblack8 (5=.) (1=4) (4=1) (2=3) (3=2), gen(GHbb8)

recode Qmuslim1 (5=.) (1=1) (2=2) (3=3) (4=4), gen(GHmu1)
recode Qmuslim2 (5=.) (1=4) (4=1) (2=3) (3=2), gen(GHmu2)
recode Qmuslim3 (5=.) (1=1) (2=2) (3=3) (4=4), gen(GHmu3)
recode Qmuslim4 (5=.) (1=4) (4=1) (2=3) (3=2), gen(GHmu4)
recode Qmuslim5 (5=.) (1=4) (4=1) (2=3) (3=2), gen(GHmu5)
recode Qmuslim6 (5=.) (1=4) (4=1) (2=3) (3=2), gen(GHmu6)
recode Qmuslim7 (5=.) (1=4) (4=1) (2=3) (3=2), gen(GHmu7)
recode Qmuslim8 (5=.) (1=4) (4=1) (2=3) (3=2), gen(GHmu8)

recode Qeast1 (5=.) (1=1) (2=2) (3=3) (4=4), gen(GHee1)
recode Qeast2 (5=.) (1=4) (4=1) (2=3) (3=2), gen(GHee2)
recode Qeast3 (5=.) (1=1) (2=2) (3=3) (4=4), gen(GHee3)
recode Qeast4 (5=.) (1=4) (4=1) (2=3) (3=2), gen(GHee4)
recode Qeast5 (5=.) (1=4) (4=1) (2=3) (3=2), gen(GHee5)
recode Qeast6 (5=.) (1=4) (4=1) (2=3) (3=2), gen(GHee6)
recode Qeast7 (5=.) (1=4) (4=1) (2=3) (3=2), gen(GHee7)
recode Qeast8 (5=.) (1=4) (4=1) (2=3) (3=2), gen(GHee8)

recode Qwhite1 (5=.) (1=1) (2=2) (3=3) (4=4), gen(GHwb1)
recode Qwhite2 (5=.) (1=4) (4=1) (2=3) (3=2), gen(GHwb2)
recode Qwhite3 (5=.) (1=1) (2=2) (3=3) (4=4), gen(GHwb3)
recode Qwhite4 (5=.) (1=4) (4=1) (2=3) (3=2), gen(GHwb4)
recode Qwhite5 (5=.) (1=4) (4=1) (2=3) (3=2), gen(GHwb5)
recode Qwhite6 (5=.) (1=4) (4=1) (2=3) (3=2), gen(GHwb6)
recode Qwhite7 (5=.) (1=4) (4=1) (2=3) (3=2), gen(GHwb7)
recode Qwhite8 (5=.) (1=4) (4=1) (2=3) (3=2), gen(GHwb8)


*********************************************************************
* TABLE A.2B IN THE APPENDIX:
*	Descriptive Statistics of Independent Variables, 2016 
*	(before multiple imputation) 
*********************************************************************

* keep only White British respondents:
keep if Ethnicity==1
** Note: 174 respondents deleted

* descriptives before imputation, for non-imputed variables only
** NOTE: temporarily create i.work_status, then delete and re-do after imputation

* work status (already 31 missing in original code (coded with missing value code .a)
recode Work_stat (1=1) (2/3 =2) (4=3) (5=4) (6=5) (7/8 = 6), into(work_status)
label define work_status 1 "working full time" 2 "working part time" 3 "full time student" 4 "retired" 5 "unemployed" 6 "not working"
label value work_status work_status
label var work_status "working status"

* (decoupled) threats:
sum threat1 threat2 threat3 threat4 threat5
* other:
sum female Age edu_age i.SocialGrade i.work_status UKborn 
** to obtain descriptives for first categories of SocialGrade and work_status:
sum ib(last).SocialGrade ib(last).work_status 

drop work_status


*********************************************************************
* TABLE A.4B IN THE APPENDIX:  
*	Associations between Threats under Decoupled Conditions, 2016
*********************************************************************

* In order to estimate correlations and their level of significance with survey data:
* (1) use correlate with aweights for point estimates of the correlation
* (2) use svy: regress for p-values 
*	Do svy: regress y x and svy: regress x y and take the biggest p-value, which is the conservative thing to do

* decoupled
pwcorr threat1 threat2 threat3 threat4 threat5 [aweight=W8], sig obs

svyset [pweight=W8]
svy: reg threat1 threat2 
svy: reg threat2 threat1 
svy: reg threat1 threat3 
svy: reg threat3 threat1 
svy: reg threat1 threat4 
svy: reg threat4 threat1 
svy: reg threat1 threat5 
svy: reg threat5 threat1 
svy: reg threat2 threat3 
svy: reg threat3 threat2 
svy: reg threat2 threat4 
svy: reg threat4 threat2 
svy: reg threat2 threat5 
svy: reg threat5 threat2 
svy: reg threat3 threat4 
svy: reg threat4 threat3 
svy: reg threat3 threat5 
svy: reg threat5 threat3 
svy: reg threat4 threat5 
svy: reg threat5 threat4 

svyset, clear


*********************************************************************
* MULTIPLE IMPUTATION
*********************************************************************

* impute (use recoded var in which missing (often code 5) is set to missing "." 
* only exception is Work_stat and Socialgrade as there is more info in original variables

set seed 974302623
mi set mlong
mi register imputed auth1 auth2 auth3 est1 est2 est3 est4 est5 GHbb1 GHbb2 GHbb3 GHbb4 GHbb5 GHbb6 GHbb7 GHbb8 GHmu1 GHmu2 GHmu3 GHmu4 GHmu5 GHmu6 GHmu7 GHmu8 GHee1 GHee2 GHee3 GHee4 GHee5 GHee6 GHee7 GHee8 GHwb1 GHwb2 GHwb3 GHwb4 GHwb5 GHwb6 GHwb7 GHwb8 
mi impute mvn auth1 auth2 auth3 est1 est2 est3 est4 est5 GHbb1 GHbb2 GHbb3 GHbb4 GHbb5 GHbb6 GHbb7 GHbb8 GHmu1 GHmu2 GHmu3 GHmu4 GHmu5 GHmu6 GHmu7 GHmu8 GHee1 GHee2 GHee3 GHee4 GHee5 GHee6 GHee7 GHee8 GHwb1 GHwb2 GHwb3 GHwb4 GHwb5 GHwb6 GHwb7 GHwb8 = female Age edu_age i.Socialgrade i.Work_stat UKborn i.threat1 i.threat2 i.threat3 i.threat4 i.threat5 i.threat6 i.threat7, add(10) force initmcmc(em, iterate(400))
display c(seed)
/* state of random-number generator is (Eline: is this necessary to record?): 
XAAcd5e29d3a216790bc618d7bf600f45f40f42f8f2804760d303eb25acd20a86b64f9a99dbc8bc33ef7206dd0828d4b623f92fdec
> 5d019b4eaf8b5837005ee0f86d882a799a10f20fb4febfa0a1254519e3d5b09cb3a805873931cf71c16eeb62601a023903b9d463
> 1b33cb864f6f44dcf31b7c40a96af353298e0be6d11f8a24eb0ae0d1b81540abd9d7c0cb0cf248df3ea3fabe09758b0deadcb57e
> 3f4deeaabea7fcfde37b8646e59dcce8db6effe4d22f81d3fdd8ec29940e30ced11c2e60cee282c015ed32d84e65f5bc902e2718
> bcf53f00677c244a3cba2a9ceee207548a66052ad10cba625ed11697304af2ea850e067c54f6ea6bacef2508860288ea83ef3147
> 1c354c9a5d1cbc6f1dc81f2fd53333b0b89fd5d4f7bbff4586eaabc703ece73dfdd84460e959cbfd7b21f304c93f800cba0862c0
> e8751b084b5961f4b916b9df32f1eb7271b8096cce014b608473e3a4e680d29989c9f60be995851738a7756bcc193e8d2d29e3c5
> f65340bc8886cdfa57c77ef7d7d1bd730d782885ab236c36cbb0d4208686fc8f3ad2063bd869a2e188939a0986d4a8bc6391f128
> 56aad177033ffb3e52e11215e9a9cd8b439889822019f05a65b9bc2334bb6e499695734b6268f313434da7a40757ef0610456f6a
> 7515bbf98207de2c53e7956dbbeb505311052b022186916bda4b60608ddfd09d18ff9c0cf3bb51c96ad37b4b46211839061c1c5c
> e725b2edaaa8e7c7cfebba93423ac8ffba13575f5a806f7291bdda5baabc2fdad1a0eb6bfc73707744d7a4e00a28cbff78602574
> d22334761f05f7940a5a3a6cd486874226a3e0efb70bb4134c910c493327507d43c521801cff9837367c6daa141deab68c2806c2
> 49ab32422f0ab9ecc2e54815486bc91108bc3c8b30b1620a28bf3f670d821234707be212de5ae9085906ccd4aa2cfaa9f2969b55
> dacafeaabfdd3b639412ee9985157052d40b4cc03e419419d0128b68f6ec81e7525d82aae16f6f3b9633f70cade7003f2dd6c28b
> b1089008f28ec860144b716cf6c6f9cac7a7d8bf30764de486bdbc9631a71a1b995b2f6e55f026cdba257341bd0673a14351edb4
> 25d8ae972b5156861bbaa8ccf92e85a974ef64712e2618e39cec417f9730de53d749f26a3575ca82ff7dbe5f99ac423f4ebbd0b8
> 6b880734e0cb0df2bb7942538e52cb1734cff5a5f4e566aecaf2d734b832a3ae696b5a6c7bfdf087577a50e7fb4921a8f557545d
> bbca513f4deea546fe8aa0f68e7adf425707a730f2c08716f1da7683e85bdc45cd56eed02156ded0088042e0f3b8d2dfd3949c20
> 06cea3796588f9d7d58a779dc98b850a0bf3e1b74bb62b8829e6bbf33596488824ea75b3356776b71bafd0674ac72f3e816a4793
> da2cde2d4dc8ceacf6866127dc7a357fc31fcd4bec43061315af3173e62c909ad8640c77a9834153d4e70883c7013ea4927f921b
> 6ddbbe04a774b2532d201c85675cc104e47c78c686d77e6bb295a5b7e0d11064160e06b49edcc4e0a441aa6369fab616e846312a
> 0af29d40c0c9fd5f5d79f633caced3b1112248abeed1d229676142177db9180a77f9d4640fd72185b9cc9f0059479caa56c418c1
> 124a541048e94b68e89f8c03bfdc29c3a282a5d1ec95134c76c83dec4e21409858511013168976f4727c56816b3b812380c37980
> 34acb2a101819e5f9af70372f051c6508c66d5b829e2186126b7ebd1b5d1d8aadf05316f99331b8918daa8cfc852bfd300387405
> f6552852f0376b6c6de01b490fec3d3529739d451935ea7ef02bc4d7ac382bc68e5e611cdc3bb3fc06e3948c752afd39f77d96e8
> bc45acb6c3bc560a373b93bf593fa8c40f55f3a9b856d7463db6fc04ace1da46c6c7842e1e8866ad77b334e61bf42e15f5d43187
> a25460c100b3e2e9c73f31a3649b632b6d3bb7d1c11cdae7ce3a9835ccdd9af772947dc000fc43ad781876b81efd656e99e78d74
> 2834f6bbac756a0a1dca0fa706d6301df9db2749963e824efebdcb6713fbc8cfe8ef702082bd2425d149aee8a8564ded42756fcb
> 34fc2ee9401db868df00dfc4d52d7a5b43dd7992e0288bb7d6d4ddd9a49a8a2b855036438a08a5b7919333de949ca0bdeb038f60
> ad505af0443535b8babe24070dc9acd5c58c2e9aaeb47673d37074a0b241ebb233ac4e9bd1f2f07518c9bf02e1baf3bdfc1b7223
> d2ee8a78f465d6e69c9e7efd3dec62caf49afbb7cf05391c14fe409534122568e0c4b32ba292c1abbcda243771cd7e173306b2be
> de20e5233f893c15dd910b3e553d7c1b3779cd783c0b319dc3892a835ad7f12c3bada6129b187d701303e6db153bc441d87c97a8
> 0f507643f3d644abc65f4ddf9aafebc89b1d17094147f1c5714dd4e1c90d87a5bc4a1119984290928a1cbf7e8cca50514ee4734c
> d6cf94d24c8d6eaa1128d650bebeff70acad92b52c5edabe4997fcabe52ce0a4b88ad99565db2246f661b71eabca351502d37dd9
> c26fe48439db78b855ab420dba1ab6a71fec78eac0263c5a653ed4eb167c1f4c9891641aa91efbff025a95977fd0141fbf6a5329
> c94315fb87dde54c253d2f87086574a7b5241d0b831683be7ffce63eb6d9875d58ebc2754ece1ed9d6c8c4c18c2723237e14a673
> 5ce0c1c43608e0caddd25ed6607a067d8ef3feb5973fdfb37d5392f9bf99144fc2cb2d020e10f78a12ce3c606fcfd006d03b13a7
> cb0ffe5562ea2d61aa5a65e3660f782870ee0ee60a6f179b93a6d8f905eff5400b318fa588801f937b63e3ad3d1bb951817b5453
> 26f0e9be3fbb328ac01316def6e4e956fb730b1221ecac4343152942d6b88ab44a294ab81d73ca03051a52a39178075439780917
> e71c995af47219462038492099b301c65038481a79303300bf66b9a283cb19c706935c53e804d787a3c87b2db6d4db8a3c44450c
> 2be7e11eb2a773668d6f8767a87e5b43e11284c612fda3e19eab05c736ebb62500a091e405822caaa7cf0c3766310dc66353365a
> bf4ab9efa4c7ab4828d1e944603ecb76bcff9311efe354f0f073bb191a08ce74a8b5d3ae9e5116311ec05a903c0196a23a14bbb3
> ae57af37dcd655d42a3947da2b3cce9fe41ba420b1091993331fb5d7c9511838a648a0e7fa4c8a38fbb061cdfeb971ebdc1dc019
> e0e396906dd1ba8a14d2f2e3a5bd33ce43f0d567c244dbd4160ae6ebdfd42eb97cb1a498ba9c64c46c5d11753705485e8d2a88c5
> 208260b1d27aff9452e226d794bd47446a5bb33bb45add90e78d8aef0067d2d955cb25d3b728eadae4a6a60b43ed40ebd24c5a39
> c76c9b325c2e46c991b48dd9ecc810fceab808031e7109bf9aade0ec2de8e832951f9038f43221718463c2f3824904e67a85d5ce
> efafaa8c99d85a50de1f2d3a94f3a7fc9f67ba4369f482e0a3b121403a80755ad776b176f10002f5f6b44e6e2d0dcd3308b20c69
> 6103938c4a8f0c44b49e09e5eefe1032f7d3006aa612c040c7c45b60c139901b575e79279ea8a52a3eaef3a516402da67bbea653
> 30001000000f23515
*/

save "W4 imputed.dta"


*********************************************************************
* FURTHER RECODES AND DESCRIPTIVES
*********************************************************************

* work status 
recode Work_stat (1=1) (2/3 =2) (4=3) (5=4) (6=5) (7/8 = 6), into(work_status)
label define Work_status 1 "working full time" 2 "working part time" 3 "full time student" 4 "retired" 5 "unemployed" 6 "not working"
label value work_status Work_status
label var work_status "working status"

* authoritarian values, self-esteem and social distance
gen authvalues = (auth1+ auth2+ auth3)/3 
gen selfest = (est1+ est2 +est3 +est4+ est5)/5  
gen GHblack = (GHbb1 +GHbb2 +GHbb3 +GHbb4 +GHbb5 +GHbb6 +GHbb7 +GHbb8)/8
gen GHMus = (GHmu1 +GHmu2+ GHmu3 +GHmu4 +GHmu5 +GHmu6 +GHmu7 +GHmu8)/8
gen GHEEur = (GHee1 +GHee2 +GHee3+ GHee4 +GHee5 +GHee6+ GHee7+ GHee8)/8
gen GHwhite = (GHwb1 +GHwb2+ GHwb3 +GHwb4+ GHwb5 +GHwb6 +GHwb7+ GHwb8)/8

* weighting
mi svyset [pweight=W8]

* create variable indicating survey wave
gen wave=1
label define wave 0 "survey wave 1 (2011)" 1 "survey wave 4 (2016)"
label value wave wave
label var wave "survey wave"

save "W4 imputed.dta", replace


*********************************************************************
* TABLE A.3B IN THE APPENDIX:
*	Estimated Mean and Standard Error of Imputed Variables, 2016
*********************************************************************

* descriptives: estimated mean and s.e.
mi estimate: svy: mean authvalues
mi estimate: svy: mean selfest	
mi estimate: svy: mean GHblack
mi estimate: svy: mean GHMus
mi estimate: svy: mean GHEEur
mi estimate: svy: mean GHwhite

* descriptives: minimum and maximum
sum authvalues selfest GHblack GHMus GHEEur GHwhite 


*********************************************************************
* TABLE A.7B IN THE APPENDIX:
*	Predictors of Group Hostility under Decoupled Condition, 2016; 
*	Threats Entered Individually
* FIGURE 1 IN THE PAPER (2016 estimates):
*	Unstandardized OLS Coefficient Estimates and 95% Confidence Intervals of the Impact of Threats
*	on Group Hostility; Threats Entered Individually
*	NOTE: for significance test of difference between 2011 and 2016 estimates, 
**	see code for FIGURE 1 below 
*********************************************************************

mi estimate: svy: reg GHblack threat1 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest 
mi estimate: svy: reg GHblack threat2 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest 
mi estimate: svy: reg GHblack threat3 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest 
mi estimate: svy: reg GHblack threat4 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest 
mi estimate: svy: reg GHblack threat5 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest 

mi estimate: svy: reg GHMus threat1 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest 
mi estimate: svy: reg GHMus threat2 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest 
mi estimate: svy: reg GHMus threat3 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest 
mi estimate: svy: reg GHMus threat4 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest 
mi estimate: svy: reg GHMus threat5 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest 

mi estimate: svy: reg GHEEur threat1 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest
mi estimate: svy: reg GHEEur threat2 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest
mi estimate: svy: reg GHEEur threat3 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest
mi estimate: svy: reg GHEEur threat4 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest
mi estimate: svy: reg GHEEur threat5 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest

mi estimate: svy: reg GHwhite threat1 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest
mi estimate: svy: reg GHwhite threat2 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest
mi estimate: svy: reg GHwhite threat3 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest
mi estimate: svy: reg GHwhite threat4 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest
mi estimate: svy: reg GHwhite threat5 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest


*********************************************************************
* DISCUSSION IN THE PAPER OF SOME ESTIMATES IN FIGURE 1 IN TERMS OF THE IMPACT 
* ON HOSTILITY OF ONE STANDARD DEVIATION (SD) INCREASE IN COLLECTIVE AND INDIVIDUAL ECONOMIC THREAT:
**	NOTE: Only calculated for threat5 (GHEEur) and threat2 (GHEEur) 
*********************************************************************

* SD for threat5
mi estimate: svy: mean threat5
matrix b = e(b_mi)
scalar m = b[1,1]
gen threat5_v = (threat5 - m)^2 
mi estimate: svy: mean threat5_v
matrix b = e(b_mi)
scalar threat5_sd2 = b[1,1]

* SD for GHEEur
mi estimate: svy: mean GHEEur
matrix b = e(b_mi)
scalar m = b[1,1]
gen GHEEur_v = (GHEEur - m)^2 
mi estimate: svy: mean GHEEur_v
matrix b = e(b_mi)
scalar GHEEur_sd2 = b[1,1]

* Effect of threat5 on GHEEur
mi estimate: svy: reg GHEEur threat5 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest
matrix beta = e(b_mi)
display(sqrt(threat5_sd2)*beta[1,1])/sqrt(GHEEur_sd2)
** Result: a one SD increase in collective economic threat is predicted to produce a -.14272635 SD decrease in GHEEur

* SD for threat2
mi estimate: svy: mean threat2
matrix b = e(b_mi)
scalar m = b[1,1]
gen threat2_v = (threat2 - m)^2 
mi estimate: svy: mean threat2_v
matrix b = e(b_mi)
scalar threat2_sd2 = b[1,1]

* Effect of threat2 on GHEEur
mi estimate: svy: reg GHEEur threat2 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest
matrix beta = e(b_mi)
display(sqrt(threat2_sd2)*beta[1,1])/sqrt(GHEEur_sd2)
** Result: a one SD increase in individual economic threat is predicted to produce a -.0835058 SD decrease in GHEEur

drop threat5_v- threat2_v


*********************************************************************
* TABLE A.8B IN THE APPENDIX:
*	Predictors of Group Hostility under Decoupled Condition, 2016; with Covariates Shown
* FIGURE A.2 IN THE APPENDIX:
*	Unstandardized OLS Coefficient Estimates and 95% Confidence Intervals of the Impact of  
* 	Threats on Group Hostility; Threats Entered Simultaneously (2016 estimates)
**	NOTE: for significance test of difference between 2011 and 2016 estimates, 
**	see code for FIGURE A.2 below  
*********************************************************************

mi estimate: svy: reg GHblack threat1 threat2 threat3 threat4 threat5 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest
mi estimate: svy: reg GHMus threat1 threat2 threat3 threat4 threat5 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest
mi estimate: svy: reg GHEEur threat1 threat2 threat3 threat4 threat5 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest
mi estimate: svy: reg GHwhite threat1 threat2 threat3 threat4 threat5 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest


*********************************************************************
* TABLE A.9B IN THE APPENDIX:
*	Predictors of Group Hostility under Decoupled Condition, 2016; with Hostility Toward White British
* FIGURE 2 IN THE PAPER (2016 estimates):
*	Unstandardized OLS Coefficient Estimates and 95% Confidence Intervals of the Impact of Threats
*	on Group Hostility; Threats Entered Simultaneaously and with Hostility Toward White British
**	NOTE: for significance test of difference between 2011 and 2016 estimates, 
**	see code for FIGURE 2 below 
*********************************************************************

mi estimate: svy: reg GHblack GHwhite threat1 threat2 threat3 threat4 threat5 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest
mi estimate: svy: reg GHMus GHwhite threat1 threat2 threat3 threat4 threat5 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest
mi estimate: svy: reg GHEEur GHwhite threat1 threat2 threat3 threat4 threat5 female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest


*****************************************************************************************************************
*   Combining and Comparing 2011 and 2016	
*****************************************************************************************************************

use "W1 imputed.dta", clear

save "W1 W4 imputed.dta", replace

keep GHblack GHMus GHEEur GHwhite threat1 threat2 threat3 threat4 threat5 female Age edu_age SocialGrade work_status UKborn authvalues selfest treatment _mi_m _mi_id _mi_miss wave W8
drop if treatment == 1

save "W1 W4 imputed.dta", replace

use "W4 imputed.dta", clear

save "W4 imputed temp.dta", replace

keep GHblack GHMus GHEEur GHwhite threat1 threat2 threat3 threat4 threat5 female Age edu_age SocialGrade work_status UKborn authvalues selfest _mi_m _mi_id _mi_miss wave W8

save "W4 imputed temp.dta", replace

use "W1 W4 imputed.dta", clear

append using "W4 imputed temp.dta"


*********************************************************************
* FIGURE 1 IN THE PAPER:                      
*	Unstandardized OLS Coefficient Estimates and 95% Confidence Intervals of the Impact of Threats on Group Hostility; 
*	Threats Entered Individually
* 	(comparing 2011 to 2016) 
*********************************************************************

* NOTE: the following models are estimated to check whether the 2011 and 2016 effects are different at .05 level
** this is indicated by the p-value associated with the c.threat[]##wave interaction effect

mi estimate: svy: reg GHblack c.threat1##wave female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest 
mi estimate: svy: reg GHblack c.threat2##wave female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest 
mi estimate: svy: reg GHblack c.threat3##wave female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest 
mi estimate: svy: reg GHblack c.threat4##wave female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest 
mi estimate: svy: reg GHblack c.threat5##wave female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest 

mi estimate: svy: reg GHMus c.threat1##wave female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest 
mi estimate: svy: reg GHMus c.threat2##wave female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest 
mi estimate: svy: reg GHMus c.threat3##wave female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest 
mi estimate: svy: reg GHMus c.threat4##wave female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest 
mi estimate: svy: reg GHMus c.threat5##wave female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest 

mi estimate: svy: reg GHEEur c.threat1##wave female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest
mi estimate: svy: reg GHEEur c.threat2##wave female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest
mi estimate: svy: reg GHEEur c.threat3##wave female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest
mi estimate: svy: reg GHEEur c.threat4##wave female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest
mi estimate: svy: reg GHEEur c.threat5##wave female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest

mi estimate: svy: reg GHwhite c.threat1##wave female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest
mi estimate: svy: reg GHwhite c.threat2##wave female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest
mi estimate: svy: reg GHwhite c.threat3##wave female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest
mi estimate: svy: reg GHwhite c.threat4##wave female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest
mi estimate: svy: reg GHwhite c.threat5##wave female Age edu_age i.SocialGrade i.work_status UKborn authvalues selfest


*********************************************************************
* FIGURE 2 IN THE PAPER:                      
*	Unstandardized OLS Coefficient Estimates and 95% Confidence Intervals of the Impact of Threats on Group Hostility; 
*	Threats Entered Simultaneously and with Hostility Toward White British	
*	(comparing 2011 to 2016) 
*********************************************************************

* NOTE: to calculate whether the difference between the estimate for a threat in 2011 is different from the one for the same threat in 2016, 
* we calculate p-values by using the following calculation: 
* 2*normal(-abs((coef. threat[] 2011 - coef. threat[] 2016)/sqrt(std. err. threat[] 2011^2 + std. err. threat[] 2016^2)))
* coefficient estimates and standard errors are taken from the estimates for Table A9A and A9B 

* Black British
* Threat 1 (neighborhood safety)
display 2*normal(-abs((.0931242 - .0094313)/sqrt(.0441536^2 + .0271298^2)))
** p-value: .10631219
* Threat 2 (individual economic)
display 2*normal(-abs((-.028872 - -.0073306)/sqrt(.0536764^2 + .0303376^2)))
** p-value: .72680591
* Threat 3 (collective safety)
display 2*normal(-abs((.0035125 - .0134799)/sqrt(.0450737^2 + .0292336^2)))
** p-value: .85281289
* Threat 4 (cultural)
display 2*normal(-abs((.1601322 - .1733378)/sqrt(.0350183^2 + .0237411^2)))
** p-value: .75493863
* Threat 5 (collective economic)
display 2*normal(-abs((-.0427327 - -.0291809)/sqrt(.044155^2 + .0288678^2)))
** p-value: .7972673

* Muslims
* Threat 1 (neighborhood safety)
display 2*normal(-abs((.0467731 - .0434108)/sqrt(.0542704^2 + .0310232^2)))
** p-value: .9571051
* Threat 2 (individual economic)
display 2*normal(-abs((.0079859 - -.0165672)/sqrt(.0578503^2 + .032668^2)))
** p-value: .71170255
* Threat 3 (collective safety)
display 2*normal(-abs((.0528585 - -.0210769)/sqrt(.0579981^2 + .0337497^2)))
** p-value: .2705406
* Threat 4 (cultural)
display 2*normal(-abs((.2817762 - .2187632)/sqrt(.0401248^2 + .0270418^2)))
** p-value: .19281956
* Threat 5 (collective economic)
display 2*normal(-abs((-.091037 - -.0850948)/sqrt(.057773^2 + .0319274^2)))
** p-value: .92826958

* East Europeans
* Threat 1 (neighborhood safety)
display 2*normal(-abs((.0023991 - .0242707)/sqrt(.0461429^2 + .0290284^2)))
** p-value: .68826694
* Threat 2 (individual economic)
display 2*normal(-abs((-.0019248 - -.0147153)/sqrt(.0526388^2 + .0339375^2)))
** p-value: .8381807
* Threat 3 (collective safety)
display 2*normal(-abs((.0711302 - .0018616)/sqrt(.0458891^2 + .0325065^2)))
** p-value: .21804269
* Threat 4 (cultural)
display 2*normal(-abs((.1500684 - .1815412)/sqrt(.0368581^2 + .0244506^2)))
** p-value: .47673685
* Threat 5 (collective economic)
display 2*normal(-abs((-.0189427 - -.0946823)/sqrt(.0423463^2 + .0313185^2)))
** p-value: .15042805


*********************************************************************
* FIGURE A2 IN THE APPENDIX:
*	Unstandardized OLS Coefficient Estimates and 95% Confidence Intervals of the Impact of Threats on Group Hostility; 
*	Threats Entered Simultaneously
*	(comparing 2011 to 2016) 
*********************************************************************

* NOTE: to calculate whether the difference between the estimate for a threat in 2011 is different from the one for the same threat in 2016, 
* we calculate p-values by using the following calculation: 
* 2*normal(-abs((coef. threat[] 2011 - coef. threat[] 2016)/sqrt(std. err. threat[] 2011^2 + std. err. threat[] 2016^2)))
* coefficient estimates and standard errors are taken from the estimates for Table A8A and A8B 

* Black British
* Threat 1 (neighborhood safety)
display 2*normal(-abs((.0859609  - .0279043)/sqrt(.0410717 + .0289343^2)))
** p-value: .7767208
* Threat 2 (individual economic)
display 2*normal(-abs((-.0238519 - .0094857)/sqrt(.0528471^2 + .0317759^2)))
** p-value: .58876416
* Threat 3 (collective safety)
display 2*normal(-abs((.0102645 - .0219323)/sqrt(.0419237^2 + .0297984^2)))
** p-value: .82054326
* Threat 4 (cultural)
display 2*normal(-abs((.1744879 - .1827249)/sqrt(.0324962^2 + .0252254^2)))
** p-value: .84130136
* Threat 5 (collective economic)
display 2*normal(-abs((-.0243403 - -.0295574)/sqrt(.0456357^2 + .0308609^2)))
** p-value: .9245533

* Muslims
* Threat 1 (neighborhood safety)
display 2*normal(-abs((.0605185 - .0580361)/sqrt(.0522981^2 + .0311723^2)))
** p-value: .96747692
* Threat 2 (individual economic)
display 2*normal(-abs((.013024 - -.0038695)/sqrt(.0576534^2 + .0320915^2)))
** p-value: .79792968
* Threat 3 (collective safety)
display 2*normal(-abs((.0477734 - -.0138552)/sqrt(.0565146^2 + .0337392^2)))
** p-value: .34910616
* Threat 4 (cultural)
display 2*normal(-abs((.2787076 - .2262143)/sqrt(.0382944^2 + .0276221^2)))
** p-value: .26624709
* Threat 5 (collective economic)
display 2*normal(-abs((-.0825042 - -.08612)/sqrt(.0569595^2 + .0320962^2)))
** p-value: .95589601

* East Europeans
* Threat 1 (neighborhood safety)
display 2*normal(-abs((.001476 - .0331326)/sqrt(.0435333 ^2 + .0290603^2)))
** p-value: .54530726
* Threat 2 (individual economic)
display 2*normal(-abs((-.0082988 - -.0057098)/sqrt(.0517012^2 + .0337664^2)))
** p-value: .96655732
* Threat 3 (collective safety)
display 2*normal(-abs((.0871651 - .0070299)/sqrt(.0429424^2 + .0321793^2)))
** p-value: .13534661
* Threat 4 (cultural)
display 2*normal(-abs((.1690109 - .1840589)/sqrt(.0347753^2 + .0248407^2)))
** p-value: .72475295
* Threat 5 (collective economic)
display 2*normal(-abs((-.0090078 - -.0936237)/sqrt(.0423013^2 + .0317273^2)))
** p-value: .10954813

* White British
* Threat 1 (neighborhood safety)
display 2*normal(-abs((.0689058 - .0606374)/sqrt(.1072397^2 + .0276963^2)))
** p-value: .94049118
* Threat 2 (individual economic)
display 2*normal(-abs((-.0731835 - .0586692)/sqrt(.1157375^2 + .0292668^2)))
** p-value: .2693876
* Threat 3 (collective safety)
display 2*normal(-abs((.1586729 - .0158332)/sqrt(.1124717^2 + .0270404^2)))
** p-value: .2168976
* Threat 4 (cultural)
display 2*normal(-abs((.0454654 - .0230823)/sqrt(.090936^2 + .0237759^2)))
** p-value: .81177539
* Threat 5 (collective economic)
display 2*normal(-abs((.1086055 - -.0038212)/sqrt(.1126276^2 + .0287071^2)))
** p-value: .33339911


*********************************************************************
* TABLE A.6 IN THE APPENDIX:	
*	Correlations between Group Hostility Scores, 2011 and 2016
*********************************************************************

	cap program drop ecorr
	program ecorr, eclass
		version 12
		syntax [varlist] [if] [in] [aw fw] [, * ]
		if (`"`weight'"'!="") {
			local wgt `weight'`exp'
		}
		marksample touse
		correlate `varlist' `if' `in' `wgt', `options'
		tempname b V
		mata: st_matrix("`b'", vech(st_matrix("r(C)"))')
		local p = colsof(`b')
		mat `V' = J(`p',`p',0)
		local cols: colnames `b'
		mat rownames `V' = `cols'
		eret post `b' `V' [`wgt'] , obs(`=r(N)') esample(`touse')
		eret local cmd ecorr
		eret local title "Lower-diagonal correlation matrix"
		eret local vars "`varlist'"
	
	end

	cap program drop micorr
	program micorr, rclass
		tempname esthold
		_estimates hold `esthold', nullok restore
		qui mi estimate, cmdok: ecorr `0'
		tempname C_mi
		mata: st_matrix("`C_mi'", invvech(st_matrix("e(b_mi)")'))
		mat colnames `C_mi' = `e(vars)'
		mat rownames `C_mi' = `e(vars)'
		di
		di as txt "Multiple-imputation estimate of the correlation matrix"	
		di as txt "(obs=" string(e(N_mi),"%9.0g") ")"
		matlist `C_mi'
		return clear
		ret matrix C_mi = `C_mi'

	end
	
micorr GHblack GHMus GHEEur GHwhite if wave == 0
micorr GHblack GHMus GHEEur GHwhite if wave == 1
